#include "input.h"



uint8_t key_scan(void)
{
    static uint8_t key_up_record;
    static uint8_t key_down_record;
    static uint8_t key_enter_record;
    static uint8_t key_exit_record;


    if(key_up_record != bsp_GetKeyState(KID_DOWN_U))
    {
        key_up_record = bsp_GetKeyState(KID_DOWN_U);
        if(key_up_record)
        {
            return 0x01;
        }
    }

    if(key_down_record != bsp_GetKeyState(KID_DOWN_D))
    {
        key_down_record = bsp_GetKeyState(KID_DOWN_D);
        if(key_down_record)
        {
            return 0x02;
        }
    }

    if(key_enter_record != bsp_GetKeyState(KID_DOWN_R))
    {
        key_enter_record = bsp_GetKeyState(KID_DOWN_R);
        if(key_enter_record)
        {
            return 0x03;
        }
    }

  
    if(key_exit_record != bsp_GetKeyState(KID_DOWN_L))
    {
        key_exit_record = bsp_GetKeyState(KID_DOWN_L);
        if(key_exit_record)
        {
            return 0x04;
        }
    }  


    return 0x00;


}


input_e read_input(void)
{
    uint8_t ret;

    ret = key_scan();
    switch (ret)
    {
        case 0x01:
            return INPUT_UP;
        case 0x02:
            return INPUT_DOWN;
        case 0x03:
            return INPUT_ENTER;
        case 0x04:
            return INPUT_EXIT;
        default:
            return INPUT_NO_EVENT;
    }

}













